import u from 'updeep'
import request from '../util/request'
import Taro from '@tarojs/taro'
export default {
    namespace: 'environmentAssessment',
    state: {
        showCellphone:false,
        cellphone:"15162613032"
    },
    reducers: {
        updateState(state, {payload}){
            return u(payload,state);
        }
    },
    effects: {
      * addView({payload = {}}, {select, put, call}){

        let url = "/service/view/addView"
        const {data} = yield call(request, {
          url: SERVERURL + url,
          method: 'post',
          data:{
            type:"environment"
          }
        })

        if (data && data === "unauthc") {
          Taro.navigateTo({
            url: `/pages/login/index`
          })
          Taro.showToast({
            title: ("会话过时"),
            icon: 'none'
          })
        }

        let showCellphone = data.data;

        if (data.code === "000000"){
          yield put({
            type: 'updateState',
            payload: {
              showCellphone: showCellphone
            }
          })
        }
      },
      * loadHasView({payload = {}}, {select, put, call}){
        let url = "/service/view/hasView"
        const {data} = yield call(request, {
          url: SERVERURL + url,
          method: 'post',
          data:{
            type:"environment"
          }
        })

        let showCellphone = data.data;

        if (data.code === "000000"){
          yield put({
            type: 'updateState',
            payload: {
              showCellphone: showCellphone
            }
          })
        }
      }
    }
}
